var laypage = layui.laypage;

var pageNumber = getQueryString("pageNumber") || 1;
var pageSize = getQueryString("pageSize") || 8;
document.title = "t-io商务合作案例，部分为项目外包，部分为技术指导，部分为商务赞助";
function page(pageNumber, pageSize) {
    var newurl = window.location.href;
    var newurl = changeURLArg(newurl, 'pageNumber', pageNumber);
    var newurl = changeURLArg(newurl, 'pageSize', pageSize);
    var data = null;
    var title = null;
    history.pushState(data, title, newurl);

    ajax.get("/bs/page", {
        data: {
            "pageNumber": pageNumber,
            "pageSize": pageSize
        },
        success: function (resp) {
            var data = resp.data;

            log(data);
            renderList(data.list);
            //执行一个laypage实例
            // laypage.render({
            //     elem: 'page'
            //     , count: data.totalRow //数据总数，从服务端得到
            //     , curr: data.pageNumber
            //     , limit: data.pageSize
            //     , theme: '#1E9FFF'
            //     , jump: function (obj, first) {
            //         //obj包含了当前分页的所有参数，比如：pageNumber = obj.curr;  pageSize = obj.limit;
            //         // log(obj);
            //         //首次不执行
            //         if (!first) {
            //             page(obj.curr, obj.limit);
            //         }
            //     }
            // });

            laypage_render('page', data, page);
        }
    });

}

/**
 * {
      "caseimg": "/img/case/cmpp.jpg",
      "caseintro": "tio实现的中网移动CMPP3",
      "provideddate": "2018-02-26 16:45:21",
      "orderby": 2,
      "personid": 4,
      "id": 23,
      "casename": "中网移动CMPP3",
      "personqq": 270249250
    }
     {
      "caseimg": "/img/case/nb.png",
      "caseintro": "牛吧云播是一个大型直播平台，包括直播、视频、小游戏等业务，该平台的im是基于tio-core和tio-websocket完成的，http api服务是基于tio-http和tio-mvc完成的，http静态页面是基于tio-webpack完成的",
      "provideddate": "2018-02-08 09:14:40",
      "orderby": 1,
      "personid": 1,
      "id": 21,
      "casename": "牛吧云播",
      "caseurl": "https://beta.hs350.com/tio",
      "personqq": 33745965
    },
 * @param {*} item 
 */
function renderItem(item, index) {
    var i = item;
    var caseimg = res_url(i.caseimg);// || "/res/tio-ad-blue.jpg";
    var personqq = i.personqq == 0 ? "不方便提供" : i.personqq;
    var str = '';
    // str += '<div class="item___3GAX3">';
    // str += '<a href="' + caseimg + '" target="_blank"><img src="' + caseimg + '" alt="" class="img___2wYpk layui-anim layui-anim-scaleSpring"></a>';
    // str += '<div class="main___3l5MN">';
    // str += '<div class="title___TNtad">' + i.casename + '</div>';
    // str += '<div class="gen___2kHUc">';
    // str += '<span style="display:inline-block; width: 200px;">QQ: ' + personqq + '</span>';
    // str += '<span>收录时间：' + i.provideddate + '</span>';
    // str += '</div>';
    // str += '<div class="info___2_HDL">' + i.caseintro + '</div>';
    // str += '</div>';
    // str += '<div class="btn___1_HHL">';
    // if (i.caseurl) {
    //     str += '<a href="' + i.caseurl + '" target="_blank">';
    //     str += '<button type="button" class="ant-btn ant-btn-primary ant-btn-lg ant-btn-background-ghost layui-anim layui-anim-scaleSpring">';
    //     str += '<span>去看看</span>';
    //     str += '</button>';
    //     str += '</a>';
    // } else {
    //     str += '<button disabled="" type="button" class="ant-btn ant-btn-lg ant-btn-background-ghost">';
    //     str += '<span>未提供地址</span>';
    //     str += '</button>';
    // }

    // str += '</div>';
    // str += '</div>';
    // str += '';



    index = index + 1;
    var divid = 'item_' + index;
    str += '<div class="grid_item layui-anim layui-anim-scaleSpring" id="' + divid + '">';







    str += '    <div style="" class="grid_item_caseimg_wrap">';
    if (i.caseurl) {
        str += '        <a href="' + i.caseurl + '" target="_blank">';
    }

    if (caseimg) {
        str += '        <img src="' + caseimg + '" alt=""   class="grid_item_caseimg">';
    } else {
        str += '        <div class="grid_item_caseimg grid_item_caseimg_none"   style="">未提供图片</div>';
    }

    if (i.caseurl) {
        str += '</a>';
    }

    str += '    </div>';
    // str += '    <div class="title___TNtad">' + i.casename + '</div>';

   
    str += '<div class="grid_item_casename layui-anim layui-anim-scaleSpring">';
    str += i.casename;
    str += '</div>';

    str += '    <div class="info___2_HDL">' + i.caseintro + '</div>';

    // str += '    <div style="position: absolute; bottom:5px;right: 15px;">';
    // if (i.caseurl) {
    //     str += '        <a href="' + i.caseurl + '" target="_blank">';
    //     str += '            <button class="layui-btn layui-btn-normal layui-btn-radius">去看看</button>';
    //     str += '        </a>';
    // } else {
    //     str += '            <button class="layui-btn layui-btn-disabled ">未提供地址</button>';
    // }

    // str += '    </div>';


    str += '    <div class="gen___2kHUc">';
    str += '        <span title="QQ">' + personqq + '</span>';
    str += '        <span title="收录时间" style="float:right">' + i.provideddate.substring(0, 10) + '</span>';
    

    // str += '<div class="grid_item_index">';
    // str += index;
    // str += '</div>';

    str += '    </div>';
    
    str += '</div>';




    return str;
}

function renderList(list) {
    var listEle = document.getElementById("list");
    listEle.innerHTML = "";
    if (list) {
        for (var i = 0; i < list.length; i++) {
            var e = list[i];
            var itemStr = renderItem(e, i);
            listEle.innerHTML += itemStr;
        }
    }
}



page(pageNumber, pageSize);